package com.appspot.didit.test.service;

import java.util.ArrayList;

import javax.jdo.PersistenceManager;
import com.appspot.didit.client.tag.Tag;
import com.appspot.didit.server.PMF;
import com.appspot.didit.server.TagServiceImpl;
import com.appspot.didit.test.LocalServiceTestCase;

public class TagServiceTestCase extends LocalServiceTestCase {
	
	private TagServiceImpl tsi = new TagServiceImpl();
	PersistenceManager pm = PMF.get().getPersistenceManager();
	
	public void testSave() {
	    try {
	    	/*Identity id = new Identity("12345678901234567");
	    	pm.makePersistent(id);
	    	Tag tag1 = new Tag("test", id.getId(), "");
	    	Tag tag2 = tsi.save(tag1);
	    	Tag tag3 = pm.getObjectById(Tag.class, tag2.getId());
	    	assertNotNull(tag3);
	    	assertEquals("test", tag2.getTagname());
	    	assertEquals(tag2.getTagname(), tag3.getTagname());
	    	assertEquals(tag2.getCreator_id(), tag3.getCreator_id());
	    	assertEquals(id.getId(), tag3.getCreator_id());*/
	    } catch (Exception e) {
	    	System.out.println(e.toString());
	    	assertTrue(false);
	    } finally {
	      pm.close();
	    }
	}
	
	public void testUpdate() {
		/*
		 * unter entwicklung
		 */

		/*
		
		try {
	    	//Initiation
	    	Identity id = new Identity("12345678901234567");
			pm.makePersistent(id);
			Long user_id = id.getId();
	    	Tag tag0 = new Tag("test", user_id);
	    	tag0 = pm.makePersistent(tag0);
	    	//****************************
	    	tag0 = pm.detachCopy(tag0);
	    	
	    	tsi.update(tag0);
	    	Tag tag1 = pm.getObjectById(Tag.class, tag0.getId());
	    	assertEquals(tag1.getId(), tag0.getId());
	    	assertEquals(user_id, tag1.getCreator_id());
	    } catch (Exception e) {
	    	System.out.println(e.toString());
	    	assertTrue(false);
	    } finally {
	      pm.close();
	    }*/
	}
	
	public void testLoadTags() {
    	try {
    		//Initiation
        	/*UserHash uh = new UserHash("test", "test");
    		pm.makePersistent(uh);
    		Long user_id = uh.getId();
        	for(int i = 0; i < 10; i++) {
        		Tag tag0 = new Tag("test" + i, user_id, "");
        		pm.makePersistent(tag0);
        	}
        	//****************************
        	ArrayList<Tag> tags = tsi.loadTags(user_id);
        	for(int i = 1; i<100000;i++) {
        		i++;
        	}
        	assertNotNull(tags);
        	assertEquals(10, tags.size());*/
	    } catch (Exception e) {
	    	System.out.println(e.toString());
	    	assertTrue(false);
	    } finally {
	      pm.close();
	    }
	}

}
